package com.qd.common.panda.domain.entity.commodity;

import com.cdqidi.dict.annotation.FieldBind;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qd.common.dict.DictConstant;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 商品信息
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class CommodityDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "商品ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "商品ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String commodityId;
    /**
     * 商品编码
     */
    @NotBlank(message = "商品编码不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "商品编码长度不能超过{max}位", groups = DefaultGroup.class)
    private String commodityCode;
    /**
     * 商品名称
     */
    @NotBlank(message = "商品名称不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "商品名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String commodityName;
    /**
     * 商品简介
     */
    @Size(max = 200, message = "商品简介长度不能超过{max}位", groups = DefaultGroup.class)
    private String commodityIntroduction;
    /**
     * 商品价格
     */
    private BigDecimal commodityPrice;
    /**
     * 优惠值
     */
    private BigDecimal discountValue;
    /**
     * 用户售价
     */
    private BigDecimal userPrice;
    /**
     * 用户侧优惠方式
     */
    @FieldBind(targetField = "userDiscountMethodsDisplay")
    @Size(max = 50, message = "用户侧优惠方式长度不能超过{max}位", groups = DefaultGroup.class)
    private String userDiscountMethods;
    /**
     * 用户侧优惠方式显示
     */
    private String userDiscountMethodsDisplay;
    /**
     * 用户侧优惠值
     */
    private BigDecimal userDiscountValue;
    /**
     * 商品图片
     */
    @Size(max = 200, message = "商品图片长度不能超过{max}位", groups = DefaultGroup.class)
    @FieldBind(targetField = "commodityPicDisplay",processName = DictConstant.SYS_FILE_CONFIRM)
    private String commodityPic;
    /**
     * 商品图片显示
     */
    private String commodityPicDisplay;
    /**
     * 添加时间
     */
    private LocalDateTime addTime;
    /**
     * 修改时间
     */
    private LocalDateTime updateTime;
    /**
     * 删除时间
     */
    @JsonIgnore
    private LocalDateTime deleteTime;
    /**
     * 是否删除
     */
    @JsonProperty("isDeleted")
    private Integer isDeleted;
    /**
     * 是否启用
     */
    @Size(max = 64, message = "是否启用长度不能超过{max}位", groups = DefaultGroup.class)
    @FieldBind(targetField = "enableDisplay")
    private String enable;
    /**
     * 是否启用显示
     */
    private String enableDisplay;
    /**
     * 供应商
     */
    @NotBlank(message = "供应商不能为空", groups = DefaultGroup.class)
    @Size(max = 64, message = "供应商长度不能超过{max}位", groups = DefaultGroup.class)
    @FieldBind(targetField = "supplierDisplay")
    private String supplier;
    /**
     * 供应商显示
     */
    private String supplierDisplay;
    /**
     * 操作人
     */
    @FieldBind(targetField = "operatorDisplay", processName = DictConstant.SYS_LOGIN_USER)
    @Size(max = 50, message = "操作人长度不能超过{max}位", groups = DefaultGroup.class)
    private String operator;
    /**
     * 操作人显示
     */
    private String operatorDisplay;
    /**
     * 机构ID
     */
    @FieldBind(targetField = "orgIdDisplay", processName = DictConstant.SYS_ORG)
    @Size(max = 50, message = "机构ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String orgId;
    /**
     * 机构ID显示
     */
    private String orgIdDisplay;
    /**
     * 品牌
     */
    @FieldBind(targetField = "brandDisplay")
    @Size(max = 64, message = "品牌长度不能超过{max}位", groups = DefaultGroup.class)
    private String brand;
    /**
     * 品牌显示
     */
    private String brandDisplay;
    /**
     * 优惠方式
     */
    @FieldBind(targetField = "discountMethodsDisplay")
    @Size(max = 64, message = "优惠方式长度不能超过{max}位", groups = DefaultGroup.class)
    private String discountMethods;
    /**
     * 优惠方式显示
     */
    private String discountMethodsDisplay;
    /**
     * 产品形式
     */
    @FieldBind(targetField = "productFormDisplay")
    @NotBlank(message = "产品形式不能为空", groups = DefaultGroup.class)
    @Size(max = 64, message = "产品形式长度不能超过{max}位", groups = DefaultGroup.class)
    private String productForm;
    /**
     * 产品形式显示
     */
    private String productFormDisplay;
    /**
     * 是否组合商品
     */
    @FieldBind(targetField = "combinedCommodityDisplay")
    @Size(max = 50, message = "是否组合商品长度不能超过{max}位", groups = DefaultGroup.class)
    private String combinedCommodity;
    /**
     * 是否组合商品显示
     */
    private String combinedCommodityDisplay;
    /**
     * 商品描述
     */
    private CommodityDescDTO commodityDesc;
    /**
     * 图片列表
     */
    private List<CommodityPicDTO> picList;
    /**
     * 分类列表
     */
    private List<CommodityClassificationListDTO> classificationList;
    /**
     * 商品分类
     */
    private String classificationCode;

    @Override
    public void freeData() {
        this.commodityId = null;
        this.commodityCode = null;
        this.commodityName = null;
        this.commodityIntroduction = null;
        this.commodityPrice = null;
        this.discountValue = null;
        this.userDiscountMethods = null;
        this.userDiscountMethodsDisplay = null;
        this.userDiscountValue = null;
        this.commodityPic = null;
        this.addTime = null;
        this.updateTime = null;
        this.deleteTime = null;
        this.isDeleted = null;
        this.enable = null;
        this.enableDisplay = null;
        this.supplier = null;
        this.supplierDisplay = null;
        this.operator = null;
        this.operatorDisplay = null;
        this.orgId = null;
        this.orgIdDisplay = null;
        this.brand = null;
        this.brandDisplay = null;
        this.discountMethods = null;
        this.discountMethodsDisplay = null;
        this.userPrice = null;
        this.productForm = null;
        this.productFormDisplay = null;
        this.combinedCommodity = null;
        this.combinedCommodityDisplay = null;
        this.commodityPicDisplay = null;
        this.classificationCode = null;
        Optional.ofNullable(commodityDesc).ifPresent(CommodityDescDTO::freeData);
        Optional.ofNullable(picList).ifPresent(List::clear);
        Optional.ofNullable(classificationList).ifPresent(List::clear);
        super.freeData();
    }
}
